/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DetailedCriminal.java
 *
 * Created on Aug 26, 2011, 5:34:10 PM
 */
package Views;

import Controllers.CriminalController;
import Controllers.DBUtility;
import Models.Criminal;
import java.io.*;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JSpinner;

/**
 *
 * @author Pan
 */
public class EditCriminal extends javax.swing.JDialog {

    int _criminalID;

    /** Creates new form DetailedCriminal */
    public EditCriminal(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    public EditCriminal(java.awt.Frame parent, boolean modal, Criminal criminal) {
        super(parent, modal);
        initComponents();

        _criminalID = criminal.getID();
        if (criminal.getPicture() != null) {
            ImageIcon criminalPicture = new ImageIcon(criminal.getPicture());
            lblPicture.setIcon(criminalPicture);
        }
        txtPicture.setText(criminal.getPicture());
        txtFullName.setText(criminal.getFullName());
        if (!criminal.isGender()) {
            cbxGender.setSelectedIndex(1);
        }
        txtPlaceOfBirth.setText(criminal.getPlaceOfBirth());
        spnDateOfBirth.setValue(criminal.getDateOfBirth());
        txtNationality.setText(criminal.getNationality());
        spnHeight.setValue(criminal.getHeight());
        spnWeight.setValue(criminal.getWeight());
        txtHair.setText(criminal.getHair());
        txtRace.setText(criminal.getRace());
        txtOtherDescriptions.setText(criminal.getOtherDescriptions());
        txtAliases.setText(criminal.getAliases());
        if (criminal.isIsArrested()) {
            cbxGender.setSelectedIndex(1);
            spnArrestedTime.setValue(criminal.getArrestedTime());
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        lblPicture = new javax.swing.JLabel();
        btn_Close = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        txtFullName = new javax.swing.JTextField();
        cbxGender = new javax.swing.JComboBox();
        spnDateOfBirth = new javax.swing.JSpinner();
        txtNationality = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txtPicture = new javax.swing.JTextField();
        btn_BrowsePicture = new javax.swing.JButton();
        txtPlaceOfBirth = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtAliases = new javax.swing.JTextArea();
        cbxArrestStatus = new javax.swing.JComboBox();
        jLabel9 = new javax.swing.JLabel();
        spnArrestedTime = new javax.swing.JSpinner();
        jLabel10 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jLabel15 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jLabel21 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        txtOtherDescriptions = new javax.swing.JTextArea();
        spnHeight = new javax.swing.JSpinner();
        txtHair = new javax.swing.JTextField();
        spnWeight = new javax.swing.JSpinner();
        txtRace = new javax.swing.JTextField();
        btn_Submit = new javax.swing.JButton();
        jLabel11 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("New Criminal Submission Form");

        jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2));
        jPanel1.setPreferredSize(new java.awt.Dimension(613, 50));

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 24));
        jLabel1.setText("Criminal Modification Form");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addContainerGap(511, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        btn_Close.setText("Close");
        btn_Close.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_CloseActionPerformed(evt);
            }
        });

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Indentification Info"));

        jLabel5.setForeground(new java.awt.Color(255, 51, 51));
        jLabel5.setText("Date of birth (mm/dd/yyyy):");

        jLabel6.setForeground(new java.awt.Color(255, 51, 51));
        jLabel6.setText("Nationality:");

        jLabel3.setForeground(new java.awt.Color(255, 51, 51));
        jLabel3.setText("Full Name:");

        jLabel4.setForeground(new java.awt.Color(255, 51, 51));
        jLabel4.setText("Gender:");

        jLabel8.setForeground(new java.awt.Color(255, 51, 51));
        jLabel8.setText("Place of birth:");

        txtFullName.setEnabled(false);

        cbxGender.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Male", "Female" }));
        cbxGender.setEnabled(false);

        spnDateOfBirth.setModel(new javax.swing.SpinnerDateModel(new java.util.Date(-946796400000L), new java.util.Date(-946796400000L), new java.util.Date(), java.util.Calendar.DAY_OF_YEAR));
        spnDateOfBirth.setEditor(new javax.swing.JSpinner.DateEditor(spnDateOfBirth, "MM/dd/yyyy"));
        spnDateOfBirth.setEnabled(false);

        txtNationality.setEnabled(false);

        jLabel2.setText("Picture:");

        txtPicture.setEditable(false);

        btn_BrowsePicture.setText("Browse");
        btn_BrowsePicture.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_BrowsePictureActionPerformed(evt);
            }
        });

        txtPlaceOfBirth.setEnabled(false);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtFullName, javax.swing.GroupLayout.DEFAULT_SIZE, 225, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cbxGender, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtNationality, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(spnDateOfBirth, javax.swing.GroupLayout.DEFAULT_SIZE, 139, Short.MAX_VALUE))
                    .addComponent(jLabel2)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(txtPicture, javax.swing.GroupLayout.DEFAULT_SIZE, 206, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btn_BrowsePicture))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtPlaceOfBirth, javax.swing.GroupLayout.DEFAULT_SIZE, 208, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtFullName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(cbxGender, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtNationality, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addGap(6, 6, 6)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(txtPlaceOfBirth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel5)
                    .addComponent(spnDateOfBirth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtPicture, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btn_BrowsePicture)))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Criminal Activity Info"));

        jLabel7.setText("Known Alias(es):");

        txtAliases.setColumns(20);
        txtAliases.setLineWrap(true);
        txtAliases.setRows(3);
        jScrollPane1.setViewportView(txtAliases);

        cbxArrestStatus.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Not Arrested", "Arrested" }));
        cbxArrestStatus.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbxArrestStatusItemStateChanged(evt);
            }
        });

        jLabel9.setForeground(new java.awt.Color(255, 51, 51));
        jLabel9.setText("Arrest Status:");

        spnArrestedTime.setModel(new javax.swing.SpinnerDateModel(new java.util.Date(-946796400000L), new java.util.Date(-946796400000L), new java.util.Date(), java.util.Calendar.DAY_OF_MONTH));
        spnArrestedTime.setEditor(new javax.swing.JSpinner.DateEditor(spnArrestedTime, "MM/dd/yyyy"));
        spnArrestedTime.setEnabled(false);

        jLabel10.setText("Arrested Time:");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 279, Short.MAX_VALUE)
                    .addComponent(jLabel7)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel10)
                            .addComponent(jLabel9))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(cbxArrestStatus, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(spnArrestedTime, javax.swing.GroupLayout.PREFERRED_SIZE, 92, Short.MAX_VALUE))))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(cbxArrestStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(spnArrestedTime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Appearances"));

        jLabel15.setForeground(new java.awt.Color(255, 51, 51));
        jLabel15.setText("Height (cm):");

        jLabel17.setForeground(new java.awt.Color(255, 51, 51));
        jLabel17.setText("Weight (Kg):");

        jLabel19.setForeground(new java.awt.Color(255, 51, 51));
        jLabel19.setText("Hair Color:");

        jLabel21.setForeground(new java.awt.Color(255, 51, 51));
        jLabel21.setText("Race:");

        jLabel22.setText("Other Appearance Descriptions:");

        txtOtherDescriptions.setColumns(20);
        txtOtherDescriptions.setLineWrap(true);
        txtOtherDescriptions.setRows(5);
        jScrollPane2.setViewportView(txtOtherDescriptions);

        spnHeight.setModel(new javax.swing.SpinnerNumberModel(150, 1, 1000, 1));

        spnWeight.setModel(new javax.swing.SpinnerNumberModel(60, 1, 1000, 1));

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 433, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(jLabel15)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(spnHeight, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(jLabel17)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(spnWeight, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(12, 12, 12)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel19)
                            .addComponent(jLabel21))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtRace, javax.swing.GroupLayout.DEFAULT_SIZE, 263, Short.MAX_VALUE)
                            .addComponent(txtHair, javax.swing.GroupLayout.DEFAULT_SIZE, 263, Short.MAX_VALUE)))
                    .addComponent(jLabel22, javax.swing.GroupLayout.Alignment.LEADING))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(spnHeight, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel19)
                    .addComponent(txtHair, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel17)
                    .addComponent(jLabel21)
                    .addComponent(spnWeight, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtRace, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel22)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE)
                .addContainerGap())
        );

        btn_Submit.setText("Submit");
        btn_Submit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_SubmitActionPerformed(evt);
            }
        });

        jLabel11.setForeground(new java.awt.Color(255, 51, 51));
        jLabel11.setText("Red Label: Mandatory fields. Some fields will not be modifiable to prevent vandalism.");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 806, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel11)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 239, Short.MAX_VALUE)
                        .addComponent(btn_Submit)
                        .addGap(18, 18, 18)
                        .addComponent(btn_Close))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lblPicture)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lblPicture)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(btn_Close)
                    .addComponent(btn_Submit))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btn_CloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_CloseActionPerformed
        this.dispose();
    }//GEN-LAST:event_btn_CloseActionPerformed

    private void btn_BrowsePictureActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_BrowsePictureActionPerformed
        //This will start off the filechooser dialog at our default ~/Images/Criminals folder
        JFileChooser fileChooser = new JFileChooser(System.getProperty("user.dir") + "/Images/Criminals/");
        if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            //The process below will copy the selected picture to the application's folder for long-term access
            File sourceImage = new File(fileChooser.getSelectedFile().getPath());
            File destImage = new File(System.getProperty("user.dir") + "/Images/Criminals/" + fileChooser.getSelectedFile().getName());
            //If the chosen image is already in our Images folder, the copy process with not be done
            if (!sourceImage.getPath().equals(destImage.getPath())) {
                try {
                    destImage.createNewFile();
                    InputStream in = new FileInputStream(sourceImage);
                    OutputStream out = new FileOutputStream(destImage);
                    byte[] buf = new byte[1024];
                    int len;
                    while ((len = in.read(buf)) > 0) {
                        out.write(buf, 0, len);
                    }

                    in.close();
                    out.close();
                } catch (IOException ex) {
                    Logger.getLogger(EditCriminal.class.getName()).log(Level.SEVERE, null, ex);
                    destImage.delete();
                }
            }
            //Finally, paste the picture's relative path to the textfield
            txtPicture.setText("Images/Criminals/" + destImage.getName());
            ImageIcon _picture = new ImageIcon(destImage.getPath());
            lblPicture.setIcon(_picture);
        }
    }//GEN-LAST:event_btn_BrowsePictureActionPerformed

    private void cbxArrestStatusItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbxArrestStatusItemStateChanged
        switch (cbxArrestStatus.getSelectedIndex()) {
            case 0:
                spnArrestedTime.setEnabled(false);
                break;
            case 1:
                spnArrestedTime.setEnabled(true);
                break;
        }
    }//GEN-LAST:event_cbxArrestStatusItemStateChanged

    private void btn_SubmitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_SubmitActionPerformed
        Criminal _criminal = new Criminal();
        SimpleDateFormat formatter = new SimpleDateFormat("DD/mm/yyyy");
        SimpleDateFormat ArrestedTimeFormat = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss");

        _criminal.setID(_criminalID);
        _criminal.setFullName(txtFullName.getText().trim());
        _criminal.setGender((cbxGender.getSelectedIndex() == 0));
        //The Java language creates a hinderance at inserting a Date object,
        //we have to format the value object into a string first
        //then parse it back into a Date object
        try {
            String dateString = formatter.format(spnDateOfBirth.getValue());
            _criminal.setDateOfBirth(formatter.parse(dateString));
        } catch (ParseException ex) {
            Logger.getLogger(EditCriminal.class.getName()).log(Level.SEVERE, null, ex);
        }
        _criminal.setPicture(txtPicture.getText().trim());
        _criminal.setPlaceOfBirth(txtPlaceOfBirth.getText().trim());
        _criminal.setNationality(txtNationality.getText().trim());
        _criminal.setHeight(Short.parseShort(spnHeight.getValue().toString()));
        _criminal.setWeight(Short.parseShort(spnWeight.getValue().toString()));
        _criminal.setHair(txtHair.getText().trim());
        _criminal.setRace(txtRace.getText().trim());
        _criminal.setAliases(txtAliases.getText().trim());
        _criminal.setOtherDescriptions(txtOtherDescriptions.getText());
        if (cbxArrestStatus.getSelectedIndex() == 0) {
            //If the criminal is currently not arrested...
            _criminal.setIsArrested(false);
            _criminal.setArrestedTime(null);
        } else {
            //If the criminal is currently arrested...
            _criminal.setIsArrested(true);
            try {
                String dateString = ArrestedTimeFormat.format(spnArrestedTime.getValue());
                _criminal.setArrestedTime(ArrestedTimeFormat.parse(dateString));
            } catch (ParseException ex) {
                Logger.getLogger(EditCriminal.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        //Now we've loaded out Criminal instance, send it to the Controller to process
        if (CriminalController.EditCriminal(_criminal)) {
            JOptionPane.showMessageDialog(null, "Criminal modified.");
        } else {
            JOptionPane.showMessageDialog(null, "Submission failed.");
        }
        this.dispose();
    }//GEN-LAST:event_btn_SubmitActionPerformed
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                EditCriminal dialog = new EditCriminal(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_BrowsePicture;
    private javax.swing.JButton btn_Close;
    private javax.swing.JButton btn_Submit;
    private javax.swing.JComboBox cbxArrestStatus;
    private javax.swing.JComboBox cbxGender;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel lblPicture;
    private javax.swing.JSpinner spnArrestedTime;
    private javax.swing.JSpinner spnDateOfBirth;
    private javax.swing.JSpinner spnHeight;
    private javax.swing.JSpinner spnWeight;
    private javax.swing.JTextArea txtAliases;
    private javax.swing.JTextField txtFullName;
    private javax.swing.JTextField txtHair;
    private javax.swing.JTextField txtNationality;
    private javax.swing.JTextArea txtOtherDescriptions;
    private javax.swing.JTextField txtPicture;
    private javax.swing.JTextField txtPlaceOfBirth;
    private javax.swing.JTextField txtRace;
    // End of variables declaration//GEN-END:variables

    private boolean IsValidate() {
        if (txtFullName.getText().trim().isEmpty()) {
            JOptionPane.showMessageDialog(null, "Full Name required.");
            return false;
        }
        if (txtPlaceOfBirth.getText().trim().isEmpty()) {
            JOptionPane.showMessageDialog(null, "Place of Birth required.");
            return false;
        }
        if (txtHair.getText().trim().isEmpty()) {
            JOptionPane.showMessageDialog(null, "Hair color required.");
            return false;
        }
        if (txtRace.getText().trim().isEmpty()) {
            JOptionPane.showMessageDialog(null, "Race required.");
            return false;
        }
        return true;
    }
}
